<template>
  <div>
    <popup ref="popup" @confirm="popConfirm">
      <a-form
        slot="customCount"
        :form="form"
        :label-col="{ span: 5 }"
        :wrapper-col="{ span: 19 }"
      >
        <a-form-item
          v-for="(domain, index) in formData"
          :label="domain.controlLable"
          :key="index"
        >
          <a-radio-group
            v-model="domain.controlValue"
            v-if="'radio' == domain.controlType"
          >
            <a-radio
              v-for="(defaults, indexd) in domain.controlDefault.split(
                '--__--'
              )"
              :value="indexd"
              :key="indexd"
            >
              {{ defaults.split(":")[0] }}
            </a-radio>
          </a-radio-group>
          <a-textarea
            v-model="domain.controlValue"
            v-if="'textarea' == domain.controlType"
            :auto-size="{ minRows: 3, maxRows: 5 }"
          />
        </a-form-item>
      </a-form>
    </popup>
  </div>
</template>

<script>
import popup from "../pop/popup.vue";
import { formDataSave, updateBaseInfo } from "@/api";
export default {
  name: "dynamicForm",
  components: {
    popup,
  },
  props: {
    formData: {
      type: Array,
      default: () => [],
    },
    recordData: {
      type: Object,
      default: () => {},
    },
  },
  data() {
    return {
      form: this.$form.createForm(this),
    };
  },
  created() {},
  methods: {
    async popConfirm() {
      // console.log(JSON.parse(sessionStorage.getItem("userInfo")).roles[0].roleKey,'asdadasdasdasda')
      console.log(this.recordData);
      console.log(this.formData);
      let user = JSON.parse(sessionStorage.getItem("userInfo")).roles[0]
        .roleKey;
      console.log(user);
      const res = await formDataSave(this.recordData.taskId, this.formData);
      if (res.code != 200) return this.$message.error(res.msg);
      if (user == "zjzz") {
        const res2 = await updateBaseInfo({
          baseId: this.recordData.baseId,
          opinion: this.formData[0].controlValue,
        });
        console.log(res2);
        if (res.code != 200) return this.$message.error(res.msg);
      }

      this.$notification["success"]({
        message: "提示",
        description: res.msg,
      });
      this.hideForm();

      this.$emit("confirm");
    },
    // showForm
    showForm() {
      this.$refs.popup.showPop();
    },
    hideForm() {
      this.$refs.popup.hidePop();
    },
  },
};
</script>

<style>
</style>